//
//  ViewController.m
//  UI04_homework(QQMusic)
//
//  Created by Hanlingyu on 16/7/19.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "ViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface ViewController ()



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor yellowColor];
    

    
    self.backgroundImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.backgroundImageView.image = [UIImage imageNamed:@"1.jpg"];
    [self.view addSubview:self.backgroundImageView];
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:effect];
    visualView.frame = self.backgroundImageView.frame;
    
    [self.backgroundImageView addSubview:visualView];
    
    
    
    
    NSArray *buttonNameArray = @[@"player_btn_favorite_normal.jpg", @"player_btn_random_normal.jpg", @"player_btn_download_normal.jpg", @"player_btn_share_normal.jpg", @"player_btn_playlist_normal.jpg"];
    
    for (NSInteger i = 0; i < 5; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(10 + WIDTH / 5 * i, HEIGHT - 60, WIDTH / 5 - 20, 50);
        button.backgroundColor = [UIColor clearColor];
        [button setImage:[UIImage imageNamed:buttonNameArray[i]] forState:UIControlStateNormal];
        button.tag = 1000 + i;
        if (i == 0) {
            [button addTarget:self action:@selector(favouriteMusic:) forControlEvents:UIControlEventTouchUpInside];
        }
        [self.view addSubview:button];
        
    }
    
    
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(60, HEIGHT / 5 * 4 - 20, WIDTH - 120, 40)];
   ;
    [self.slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [self.slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    [self.slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    [self.view addSubview:self.slider];
    
    self.musicImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 70, WIDTH - 70)];
    self.musicImageView.layer.cornerRadius = (WIDTH - 70) / 2;
    self.musicImageView.layer.masksToBounds = YES;
    self.musicImageView.layer.borderWidth = 7;
    self.musicImageView.layer.borderColor = [UIColor colorWithRed:0.256f green:0.256f blue:0.256f alpha:0.7f].CGColor;
    self.musicImageView.layer.shadowOffset = CGSizeMake(0, 3);
    self.musicImageView.image = [UIImage imageNamed:@"4.jpg"];
    self.musicImageView.center = CGPointMake(WIDTH / 2, 330);
    self.musicImageView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.musicImageView];
    
    
    
    
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.frame = CGRectMake(0, 0, 60, 60);
    self.playButton.center = CGPointMake(WIDTH / 2, 640);
    self.playButton.backgroundColor = [UIColor clearColor];
    [self.playButton setImage:[UIImage imageNamed:@"player_btn_play_normal.jpg"] forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(playMusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.playButton];
    
    self.nextMusicButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextMusicButton.frame = CGRectMake(0, 0, 55, 55);
    self.nextMusicButton.center = CGPointMake(WIDTH / 2 + 90, 640);
    self.nextMusicButton.backgroundColor = [UIColor clearColor];
    [self.nextMusicButton setImage:[UIImage imageNamed:@"player_btn_next_normal"] forState:UIControlStateNormal];
    [self.nextMusicButton addTarget:self action:@selector(nextMusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.nextMusicButton];
    
    self.lastMusicButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.lastMusicButton.frame = CGRectMake(0, 0, 55, 55);
    self.lastMusicButton.center = CGPointMake(WIDTH / 2 - 90, 640);
    self.lastMusicButton.backgroundColor = [UIColor clearColor];
    [self.lastMusicButton setImage:[UIImage imageNamed:@"player_btn_pre_normal"] forState:UIControlStateNormal];
    [self.lastMusicButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.lastMusicButton];

    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    self.pageControl.center = CGPointMake(WIDTH / 2, 560);
    self.pageControl.backgroundColor = [UIColor clearColor];
    self.pageControl.numberOfPages = 3;
    self.pageControl.currentPage = 1;
    [self.view addSubview:self.pageControl];
    
    self.musicTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 30, 20)];
    self.musicTextLabel.center = CGPointMake(WIDTH / 2, 535);
    self.musicTextLabel.text = @"今夕何夕 见此良人 如月之恒";
    self.musicTextLabel.font = [UIFont systemFontOfSize:15 weight:2];
    self.musicTextLabel.textAlignment = NSTextAlignmentCenter;
    self.musicTextLabel.backgroundColor = [UIColor clearColor];
    self.musicTextLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:self.musicTextLabel];
    
    
    
    self.backLastPageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backLastPageButton.frame = CGRectMake(0, 20, 75, 55);
    self.backLastPageButton.backgroundColor = [UIColor clearColor];
    [self.backLastPageButton setImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    [self.lastMusicButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.backLastPageButton];
    
    self.moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.moreButton.frame = CGRectMake(WIDTH - 75, 20, 75, 55);
    self.moreButton.backgroundColor = [UIColor clearColor];
    [self.moreButton setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
    [self.moreButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.moreButton];

    
    self.musicTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 2, 44)];
    self.musicTitleLabel.backgroundColor = [UIColor clearColor];
    self.musicTitleLabel.center = CGPointMake(WIDTH / 2, 44);
    self.musicTitleLabel.textAlignment = 1;
    self.musicTitleLabel.text = @"湫兮如风";
    self.musicTitleLabel.textColor = [UIColor whiteColor];
    self.musicTitleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:self.musicTitleLabel];
    
    self.authorNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
    self.authorNameLabel.center = CGPointMake(WIDTH / 2, 84);
    self.authorNameLabel.backgroundColor = [UIColor clearColor];
    self.authorNameLabel.text = @"徐佳莹";
    self.authorNameLabel.font = [UIFont systemFontOfSize:14];
    self.authorNameLabel.textAlignment = NSTextAlignmentCenter;
    self.authorNameLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:self.authorNameLabel];
    
    
    self.leftLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    self.leftLine.center = CGPointMake(WIDTH / 2 - self.authorNameLabel.frame.size.width / 2 - 15, 84);
    self.leftLine.backgroundColor = [UIColor clearColor];
    self.leftLine.text = @"—";
    self.leftLine.textAlignment = NSTextAlignmentCenter;
    self.leftLine.textColor = [UIColor whiteColor];
    [self.view addSubview:self.leftLine];
    
    self.rightLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    self.rightLine.center = CGPointMake(WIDTH / 2 + self.authorNameLabel.frame.size.width / 2 + 15, 84);
    self.rightLine.backgroundColor = [UIColor clearColor];
    self.rightLine.text = @"—";
    self.rightLine.textAlignment = NSTextAlignmentCenter;
    self.rightLine.textColor = [UIColor whiteColor];
    [self.view addSubview:self.rightLine];

    
    UIView *buttonBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    buttonBackGroundView.backgroundColor = [UIColor clearColor];
    buttonBackGroundView.center = CGPointMake(WIDTH / 2, 124);
    [self.view addSubview:buttonBackGroundView];
    
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 45, 20)];
    self.timeLabel.center = CGPointMake(30, HEIGHT / 5 * 4 );
    self.timeLabel.backgroundColor = [UIColor clearColor];
    self.timeLabel.text = @"00:00";
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:self.timeLabel];
    
    self.totalTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 45, 20)];
    self.totalTimeLabel.center = CGPointMake(WIDTH - 30, HEIGHT / 5 * 4 );
    self.totalTimeLabel.backgroundColor = [UIColor clearColor];
    self.totalTimeLabel.text = @"04:50";
    self.totalTimeLabel.font = [UIFont systemFontOfSize:13];
    self.totalTimeLabel.textAlignment = NSTextAlignmentCenter;
    self.totalTimeLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:self.totalTimeLabel];

    
    self.qualityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.qualityButton.frame = CGRectMake(0, 0, 60, 40);
    self.qualityButton.backgroundColor = [UIColor clearColor];
    [self.qualityButton setImage:[UIImage imageNamed:@"player_btn_bz_sel_normal"] forState:UIControlStateNormal];
    [self.qualityButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [buttonBackGroundView addSubview:self.qualityButton];
    
    self.typeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.typeButton.frame = CGRectMake(self.qualityButton.frame.size.width + 10, 0, 50, 40);
    self.typeButton.backgroundColor = [UIColor clearColor];
    [self.typeButton setImage:[UIImage imageNamed:@"player_btn_mv_normal"] forState:UIControlStateNormal];
    [self.typeButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [buttonBackGroundView addSubview:self.typeButton];

    self.dtsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.dtsButton.frame = CGRectMake(self.typeButton.frame.size.width + self.qualityButton.frame.size.width + 20, 10, 40, 20);
    self.dtsButton.backgroundColor = [UIColor clearColor];
    [self.dtsButton setImage:[UIImage imageNamed:@"player_btn_dts_off"] forState:UIControlStateNormal];
    [self.dtsButton addTarget:self action:@selector(lastMusic:) forControlEvents:UIControlEventTouchUpInside];
    [buttonBackGroundView addSubview:self.dtsButton];
    
    buttonBackGroundView.frame = CGRectMake(0, 0, self.qualityButton.frame.size.width + self.typeButton.frame.size.width + self.dtsButton.frame.size.width + 20, 40);
    buttonBackGroundView.center = CGPointMake(WIDTH / 2, 124);
}

- (void)favouriteMusic:(UIButton *)favouriteButton {
    favouriteButton = [self.view viewWithTag:1000];
    [favouriteButton setImage:[UIImage imageNamed:@"player_btn_favorited_normal"] forState:UIControlStateNormal];
    [favouriteButton removeTarget:self action:@selector(favouriteMusic:) forControlEvents:UIControlEventTouchUpInside];
    [favouriteButton addTarget:self action:@selector(hateMusic:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)hateMusic:(UIButton *)hateButton {
    hateButton = [self.view viewWithTag:1000];
    [hateButton setImage:[UIImage imageNamed:@"player_btn_favorite_normal"] forState:UIControlStateNormal];
    [hateButton removeTarget:self action:@selector(hateMusic:) forControlEvents:UIControlEventTouchUpInside];
    [hateButton addTarget:self action:@selector(favouriteMusic:) forControlEvents:UIControlEventTouchUpInside];
}


- (void)nextMusic:(UIButton *)nextMusicButton {
    NSLog(@"下一曲");
}

- (void)lastMusic:(UIButton *)lastMusicButton {
    NSLog(@"上一曲");
}

- (void)playMusic:(UIButton *)playButton {
    NSLog(@"播放");
    [playButton setImage:[UIImage imageNamed:@"player_btn_pause_normal.jpg"] forState:UIControlStateNormal];

    [playButton removeTarget:self action:@selector(playMusic:) forControlEvents:UIControlEventTouchUpInside];
    [playButton addTarget:self action:@selector(pauseMusic:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)pauseMusic:(UIButton *)pauseButton {
    NSLog(@"暂停");
    [pauseButton setImage:[UIImage imageNamed:@"player_btn_play_normal.jpg"] forState:UIControlStateNormal];
    [pauseButton removeTarget:self action:@selector(pauseMusic:) forControlEvents:UIControlEventTouchUpInside];
    [pauseButton addTarget:self action:@selector(playMusic:) forControlEvents:UIControlEventTouchUpInside];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
